package com.chaoxuan.uebt.activity;

import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TextView;

import com.chaoxuan.uebt.R;
import com.chaoxuan.uebt.model.News;
import com.chaoxuan.uebt.utils.BaseSubscriber;
import com.chaoxuan.uebt.utils.MyWebViewClient;
import com.chaoxuan.uebt.utils.RetrofitUtils;

public class NewDetailActivity extends BaseActivity{
    WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_detail);

        initTitle();

        webView=(WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDefaultTextEncodingName("UTF -8");//设置默认为utf-8
        webView.setWebViewClient(new MyWebViewClient());

        String id= getIntent().getStringExtra("id");
        subscribe(RetrofitUtils.getAPIService().detailNews(id), new BaseSubscriber<News>() {
            @Override
            public void onSuccess(News data) {
                show(data);
            }
        });



    }

    private void show(News n){
        TextView tvTitle=(TextView) findViewById(R.id.tv_newtitle);
        TextView tvPubtime=(TextView) findViewById(R.id.tv_pubtime);
        TextView tvRefer=(TextView) findViewById(R.id.tv_refer);
        tvTitle.setText(n.getTitle());
        tvPubtime.setText(n.getPublish_time());
        tvRefer.setText(n.getSource());
        String content=n.getContent().replaceAll("src=\"","src=\"http://www.chaoxuan.io");
        webView.loadData(content, "text/html; charset=UTF-8", null);

    }
}
